#  author:张靖昆 date:2020/3/6 name:test IDE:PyCharm
# 1.设计一个登录函数、实现根据用户名和密码登录
user = {'id': "admin", 'psd': '666'}
def login(user_id, password):
    list01=[]
    for i in user:
        list01.append('name')
    if user_id in list01:
        for j in range(list01):
            if user_id==list01[j]:
                if user_id==user[j].get('name') and  password==user_id[j].get('psd'):
                    return ("登录成功")
                else:
                    return ("密码错误") # 返回值
    else :
        return ('用户不存在')

# 实现登录功能

id = input("用户名：")
psd = input('密码：')
# 传值，把数据传入方法中
print(login(id,psd))


#2. 设计一个函数实现根据传入key完成字典的排序
'''
def sort_dict(字典,key):
  return 排好序的字典
'''
goods= [  {'id':'001',"user_name":'admin','user_password':'888','age':20},
    {'id':'002',"user_name":'joke','user_password':'888','age':21},
    {'id':'003',"user_name":'nose','user_password':'888','age':11}
]
def sort_by_age(good):
    return good['age']
goods.sort(key=sort_by_age)
print(goods)
sort_by_age(goods,'age')
